import { combineReducers } from 'redux'

export const initialState = {
	count: 0,
	input: '',
	time:0,
	expression:'',
	error: ''
}

function counter(state = initialState, action) {
	const {count} = state;
	switch (action.type) {
		case 'COUNTER_ADD':
			return {count : count + 1};
		case 'COUNTER_SUB':
			return {count : count - 1};
		default:
			return state;
	}
}

// export default counter


function calculation(state = initialState, action) {
	switch (action.type) {
		case 'CALCULATION':
			return {input :  action.result ,
					time: state.time+1 ,
					expression: action.expression,
					error: action.error
				};
		default:
			return state;
	}
}

// export default calculation

export default combineReducers({
	counter,
	calculation
})